package vnreal.resources;

import vnreal.ExchangeParameter;
import vnreal.algorithms.utils.MiscelFunctions;
import vnreal.constraints.AbstractConstraint;
import vnreal.constraints.ILinkConstraint;
import vnreal.demands.AbstractDemand;
import vnreal.demands.DemandVisitorAdapter;
import vnreal.network.Link;
import vnreal.network.NetworkEntity;

public final class Length extends AbstractResource implements ILinkConstraint {
	private double length;

	public Length(Link<? extends AbstractConstraint> owner) {
		super(owner);
	}

	@ExchangeParameter
	public void setLength(Double length) {
		this.length = length;
	}

	@ExchangeParameter
	public Double getLength() {
		return this.length;
	}

	public Double getSubLinkLength() {
		return MiscelFunctions.roundThreeDecimals(length);
	}

	@Override
	public boolean accepts(AbstractDemand dem) {
		return dem.getAcceptsVisitor().visit(this);
	}

	@Override
	public boolean fulfills(AbstractDemand dem) {
		return dem.getFulfillsVisitor().visit(this);
	}

	@Override
	protected DemandVisitorAdapter createOccupyVisitor() {
		return null;
	}/*
	 * new DemandVisitorAdapter(); {
	 * 
	 * @Override public boolean visit(BandwidthDemand dem) { if (fulfills(dem))
	 * { occupiedBandwidth += MiscelFunctions.roundThreeDecimals(dem
	 * .getDemandedBandwidth()); new Mapping(dem, getThis()); return true; }
	 * else return false; } }; }
	 */

	@Override
	protected DemandVisitorAdapter createFreeVisitor() {
		return null;
	}/*
	 * new DemandVisitorAdapter() {
	 * 
	 * @Override public boolean visit(BandwidthDemand dem) { if (getMapping(dem)
	 * != null) { occupiedBandwidth -=
	 * MiscelFunctions.roundThreeDecimals(dem.getDemandedBandwidth()); return
	 * getMapping(dem).unregister(); } else return false; } }; }
	 */

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Length =");
		sb.append(getLength());
		sb.append("km");
		// sb.append(" occupied bandwidth=");
		// sb.append(occupiedBandwidth);
		// if (getMappings().size() > 0)
		// sb.append(getMappingsString());
		return sb.toString();
	}

	@Override
	public AbstractResource getCopy(NetworkEntity<? extends AbstractConstraint> owner) {

		Length clone = new Length((Link<? extends AbstractConstraint>) owner);
		clone.length = length;

		return clone;
	}

}
